package w83b.w83bOperacionesPaso.w83bMantenimientos.w83bMotivosBajaDelegado;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import w83b.w83bBeans.W83bMotivosBajaDelegadoBean;
import w83b.w83bUtilidades.W83bUtilidadesComunes;
import es.ejie.frmk.presentacion.operacion.paso.Q70ActionPasoOP;
import es.ejie.frmk.presentacion.sesiondatos.Q70ContextoEJIE;

// TODO: Auto-generated Javadoc
/**
 * The Class W83bTablaAgrupacionesOP.java.
 *
 * @author Deusto Sistemas
 */
public class W83bTablaMotivosBajaDelegadoOutOPAction extends Q70ActionPasoOP{

	
	/* (non-Javadoc)
	 * @see es.ejie.frmk.presentacion.operacion.paso.Q70ActionPasoOP#processOP(es.ejie.frmk.presentacion.sesiondatos.Q70ContextoEJIE, org.apache.struts.action.ActionErrors, org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	protected void processOP(Q70ContextoEJIE contexto, ActionErrors errores, ActionMapping mapping,
			ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		//Guardamos la accion en el contexto
	}

	/* (non-Javadoc)
	 * @see es.ejie.frmk.presentacion.operacion.paso.Q70ActionPasoOP#processForward(es.ejie.frmk.presentacion.sesiondatos.Q70ContextoEJIE, org.apache.struts.action.ActionErrors, org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	protected ActionForward processForward(Q70ContextoEJIE contexto, ActionErrors errors, ActionMapping mapping, 
			ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

		W83bMotivosBajaDelegadoBean bean = (W83bMotivosBajaDelegadoBean)contexto.get("w83bMotivosBajaDelegadoBean");
		ArrayList listaMotivos = (ArrayList)contexto.get("w83bListaMotivos");
		
		int num_paginas = listaMotivos.size()/Integer.parseInt(bean.getTotal());
		
		
		if(listaMotivos.size()%Integer.parseInt(bean.getTotal())>0){
			num_paginas++;
		}
		bean.setRows(String.valueOf(num_paginas));
		
		List listaVariables = new ArrayList();
		
		listaVariables.add("codMotivoBajaDelegado");
		listaVariables.add("descMotivoBajaDelegadoCast");
		listaVariables.add("descMotivoBajaDelegadoEusk");
		
		String varClave = "codMotivoBajaDelegado";
		
		
		String jJson = W83bUtilidadesComunes.procesarTabla((ArrayList)contexto.get("w83bListaMotivos"),listaVariables,varClave,W83bMotivosBajaDelegadoBean.class, bean);
		
		response.setContentType("text/javascript;charset=iso-8859-1");
		response.setHeader("Pragma", "cache");
		response.setHeader("Expires", "0");
		response.setHeader("Cache-Control", "private");
		response.setStatus(HttpServletResponse.SC_OK);
		PrintWriter out = response.getWriter();
		out.print(jJson);
		out.flush();
		
		return null;
	}
	


}
